<template>
    <div>
        <el-button class="app-form-footer-btn" type="primary" @click="dialogFormVisible = true"><span>邮箱地址</span></el-button>
        <el-dialog title="管理邮箱" custom-class="custom-dialog-form" :visible.sync="dialogFormVisible" :close-on-click-modal="false" @closed="dialogClose">
            <el-form ref="dialogForm" :model="seoTemp" label-position="top">
                <el-form-item label="邮箱地址" prop="adminEmailString">
                    <el-input v-model="seoTemp.adminEmailString" placeholder="请输入邮箱地址，以英文;分隔" />
                </el-form-item>
                <div class="el-message-box__btns">
                    <button type="button" class="el-button el-button--default el-button--small" @click="dialogFormVisible = false"><span>取消</span></button>
                    <button type="button" class="el-button el-button--default el-button--small el-button--primary" @click="dialogFormSubmit"><span>保存</span></button>
                </div>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
import { remakeUrl } from '@/utils'
import { adminEmailFindById, adminEmailUpdateSelective } from '@/api/email'

export default {
    name: 'SeoBtn',
    props: ['infoId', 'infoObj'],
    data: function() {
        return {
            dialogFormVisible: false,
            seoTemp: {
                adminEmailId: this.infoId,
                adminEmailString: ''
            },
            seoSave: {}
        };
    },
    created() {
        this.searchSeo()
    },
    methods: {
        remakeUrl,
        searchSeo(e) {
            if (this.infoId) {
                adminEmailFindById({ adminEmailId: this.infoId }).then(res => {
                    this.seoTemp = res.data;
                    this.seoTemp.adminEmailId = this.infoId;
                    this.seoSave = Object.assign({}, res.data);
                });
            } else {
                this.seoTemp = { ...this.infoObj }
            }
        },
        dialogFormSubmit(e) {
            var param = Object.assign({}, this.seoTemp);
            // console.log('seo', param);
            if (this.infoId) {
                adminEmailUpdateSelective(param).then(res => {
                    this.seoSave = Object.assign({}, param);
                    this.$notify({
                        message: '保存成功',
                        type: 'success'
                    });
                    this.dialogFormVisible = false;
                });
            } else {
                this.$emit('submit', param)
            }
        },
        dialogClose(e) {
            this.seoTemp = Object.assign({}, this.seoSave);
        }
    }
};
</script>

<style lang="scss" scoped>

</style>
